﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using loginSQL.Pages;
using System.IO;
using System.Drawing;
using System.Text.RegularExpressions;

namespace loginSQL.Template
{
    class Templates
    {
        public static void Save(List<AbstractPage> abstractPages, String filename)
        {
            StreamWriter sw =null;
            try
            {
                sw = new StreamWriter(filename);
                sw.WriteLine(abstractPages.Count);
                foreach (Page p in abstractPages)
                {
                    sw.WriteLine("{0} {1}", (int)p.getTopLeftX(), (int)p.getTopLeftY());
                }
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }
            }
        }

        public static List<Point> Load(String filename)
        {
            StreamReader sr = null;
            List<Point> points = new List<Point>();
            try
            {
                sr = new StreamReader(filename);
                int count = Convert.ToInt32(sr.ReadLine(),10);
                String line;
                String[] split;
                while (!sr.EndOfStream)
                {
                    line = sr.ReadLine();
                    split = Regex.Split(line, " ");
                    points.Add(new Point(Convert.ToInt32(split[0],10),Convert.ToInt32(split[1],10)));
                }
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }
            return points;
        }

        public static List<Point> StyleDefault = new List<Point>(new Point[] {
            new Point(0,0),
            new Point(0,0),
            new Point(0,0),
            new Point(0,0),
            new Point(0,0),
            new Point(0,0),
            new Point(0,0),
            new Point(0,0),
            new Point(0,0),
        });

        public static List<List<PointF>> PagesDefaultMargin = new List<List<PointF>>(new List<PointF>[]{
            new List<PointF>(new PointF[]{
                new PointF(105,32),
                new PointF(123,49),
                new PointF(123,57),
                new PointF(123,67),
                new PointF(123,77),
                new PointF(123,88)
            }),
            new List<PointF>(new PointF[]{
                new PointF(105,32),
                new PointF(123,49),
                new PointF(123,57),
                new PointF(123,67),
                new PointF(123,77),
                new PointF(123,88)
            }),
            new List<PointF>(new PointF[]{
                new PointF(105,32),
                new PointF(123,49),
                new PointF(123,57),
                new PointF(123,67),
                new PointF(123,77),
                new PointF(123,88)
            }),
            new List<PointF>(new PointF[]{
                new PointF(105,32),
                new PointF(123,49),
                new PointF(123,57),
                new PointF(123,67),
                new PointF(123,77),
                new PointF(123,88)
            }),
            new List<PointF>(new PointF[]{
                new PointF(105,32),
                new PointF(123,49),
                new PointF(123,57),
                new PointF(123,67),
                new PointF(123,77),
                new PointF(123,88)
            }),
            new List<PointF>(new PointF[]{
                new PointF(105,32),
                new PointF(123,49),
                new PointF(123,57),
                new PointF(123,67),
                new PointF(123,77),
                new PointF(123,88)
            }),
            new List<PointF>(new PointF[]{
                new PointF(105,32),
                new PointF(123,49),
                new PointF(123,57),
                new PointF(123,67),
                new PointF(123,77),
                new PointF(123,88)
            }),
            new List<PointF>(new PointF[]{
                new PointF(105,32),
                new PointF(123,49),
                new PointF(123,57),
                new PointF(123,67),
                new PointF(123,77),
                new PointF(123,88)
            }),
            new List<PointF>(new PointF[]{
                new PointF(105,32),
                new PointF(123,49),
                new PointF(123,57),
                new PointF(123,67),
                new PointF(123,77),
                new PointF(123,88)
            }),
        });
    }
}
